<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
</head>
<body>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" value="${user.realname}"  readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" value="${user.username}" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">原始密码</label>
            <div class="layui-input-inline">
                <input type="text" name="password" autocomplete="off" class="layui-input" lay-verify="required" lay-reqText="请输入原始密码"  >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="text" name="newPassword"  autocomplete="off"   class="layui-input" lay-verify="required" lay-reqText="请输入新密码"  >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="text" name="confirmPassword"  autocomplete="off"   class="layui-input" lay-verify="required" lay-reqText="请再次输入新密码"  >
            </div>
        </div>
        <div class="layui-form-item" >
            <button class="layui-btn" type="button" lay-submit lay-filter="subBtnFilter" style="width: 120px">确认</button>
            <button class="layui-btn layui-btn-primary" type="reset" style="width: 120px;margin-left: 50px">重置</button>
        </div>
    </form>

<script src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
<script>
   layui.use(['form','jquery','layer'],function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;
       /**
        * 表单提交事件监听
        */
       form.on("submit(subBtnFilter)",function (d) {
           //获取表单数据
           let formData = d.field;
           let newPassword = formData.newPassword;//新密码
           let confirmPassword = formData.confirmPassword;//再次新密码
           if (newPassword != confirmPassword){
               layer.msg("两次密码不一致!")
               return  false;
           }
           $.post("${pageContext.request.contextPath}/user.do?service=updatePwd",formData,function(rs) {
                //校验
               layer.msg(rs.msg);
               if (rs.code != 200){
                   return false;//
               }
               layer.alert("密码修改成功,请重新登录!",function (index) {
                    //window.location.href = "index.jsp";//
                    parent.location.href = "index.jsp";//
               });
               //5秒自动跳转
               setTimeout(function () {
                   parent.location.href = "index.jsp";//
               },5000);
           })
           return false;
        });

   })
</script>
</body>
</html>
